﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace QuizzAdminData
{
    public static class TeamDB
    {
        public static List<Team> GetTeams()
        {
            List<Team> teams = new List<Team>();

            SqlConnection conn = QuizzAdminDB.GetConnection();

            string selectStatement = "SELECT * FROM Teams";

            SqlCommand selectCmd = new SqlCommand(selectStatement, conn);

            try
            {
                conn.Open();
                SqlDataReader reader = selectCmd.ExecuteReader();
                while (reader.Read())
                {
                    Team team = new Team();

                    team.id = (int)reader["id"];
                    team.naam = reader["naam"].ToString();

                    teams.Add(team);
                }

                reader.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return teams;
        }
    }
}
